import { registerDecorator, ValidationOptions, ValidationArguments } from 'class-validator'


export function IsValidPassword(validationOptions?: ValidationOptions) {
    return function (object: Object, propertyName: string) {
      registerDecorator({
        name: 'isValidPassword',
        target: object.constructor,
        propertyName: propertyName,
        options: validationOptions,
        validator: {
          validate(value: any, args: ValidationArguments) {
            const passwordRegex = /^(?=.*[a-zA-Z])(?=.*\d).{6,}$/;
            console.log(passwordRegex.test(value),value)
            return typeof value === 'string' && passwordRegex.test(value);
          },
          defaultMessage(args: ValidationArguments) {
            return `${args.property} must be a valid password`;
          },
        },
      });
    };
  }
